﻿using System;
using System.Web;

using System.Linq;
using VIT.Business;
using VIT.Wedding;
using VIT.DataHelper.DataAccess;

namespace VIT.Web
{
    public partial class NewsDetail : VIT.Web.UI.VITComponent
    {
        private int vId
        {
            get
            {
                int result = 0;
                int.TryParse(Request["sId"], out result);
                return result;
            }
        }

        private void BindCommentList()
        {
            lsvComment.DataSource = VITData.GetQuery<Article_Comment>(c => c.ArticleId == vId).ToArray();
            lsvComment.DataBind();
        }

        public BLArticle bla;
        public BLCategory blc;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindCommentList();
            }

            //if (!IsPostBack)
            //{
                try
                {
                    bla = new BLArticle();
                    bla.Id = vId;
                    bla.LanguageId = Session["Language"].ToString();
                    bla.GetSingle();
                    if (bla.Id > 0)
                    {
                        //load tieu de nhom
                        blc = new BLCategory();
                        blc.LanguageId = bla.LanguageId;
                        blc.Id = bla.CategoryId;
                        blc.GetSingle();
                        
                        ////tin khac
                        //rpt.DataSource = bla.GetNewsOrther(5, bla.CategoryId);
                        //rpt.DataBind();
                    }
                }
                catch
                {
                    RedirectComponent("Home");
                }
            //}
        }

        protected void Pager_PreRender(object sender, EventArgs e)
        {
            //tin khac
            if (bla != null)
            {
                ListView.DataSource = bla.GetNewsOrther(5, vId, bla.CategoryId);
                ListView.DataBind();
            }
        }

        protected void btnSendComment_Click(object sender, EventArgs e)
        {
            var comment = new Article_Comment();
            comment.ArticleId = vId;
            comment.Name = txtNameComment.Text.Trim();
            comment.Description = txtDescriptionComment.Text.Trim();
            comment.Time = DateTime.Now;
            VITData.AddObject<Article_Comment>(comment);

            BindCommentList();
            txtNameComment.Text = string.Empty;
            txtDescriptionComment.Text = string.Empty;
            udpComment.Update();
        }
    }
}
